Import('env', 'envCython', 'arch', 'SHARED')

if SHARED:
  fxn = env.SharedLibrary
else:
  fxn = env.Library

common_libs = [
  'params.cc',
  'statlog.cc',
  'swaglog.cc',
  'util.cc',
  'i2c.cc',
  'watchdog.cc',
  'ratekeeper.cc'
]

if arch != "Darwin":
  common_libs.append('gpio.cc')

_common = fxn('common', common_libs, LIBS="json11")

files = [
  'clutil.cc',
]

_gpu_libs = []

if arch == "earch64":
  files += ['visionimg.cc']
  _gpu_libs += ['gui', 'adreno_utils']

_gpucommon = fxn('gpucommon', files, LIBS=_gpu_libs)
Export('_common', '_gpucommon', '_gpu_libs')

if GetOption('test'):
  env.Program('tests/test_util', ['tests/test_util.cc'], LIBS=[_common])
  env.Program('tests/test_swaglog', ['tests/test_swaglog.cc'], LIBS=[_common, 'json11', 'zmq', 'pthread'])
  env.Program('tests/test_ratekeeper', ['tests/test_ratekeeper.cc'], LIBS=[_common, 'json11', 'zmq', 'pthread'])

# Cython
envCython.Program('params_pyx.so', 'params_pyx.pyx', LIBS=envCython['LIBS'] + [_common, 'zmq', 'json11'])
